//init jQTouch
var jQT = new $.jQTouch({
    icon: 'jqtouch.png',
    icon4: 'jqtouch4.png',
    addGlossToIcon: false,
    startupScreen: 'jqt_startup.png',
    statusBar: 'black',
    preloadImages: [
        'themes/jqt/img/activeButton.png',
        'themes/jqt/img/back_button.png',
        'themes/jqt/img/back_button_clicked.png',
        'themes/jqt/img/blueButton.png',
        'themes/jqt/img/button.png',
        'themes/jqt/img/button_clicked.png',
        'themes/jqt/img/grayButton.png',
        'themes/jqt/img/greenButton.png',
        'themes/jqt/img/redButton.png',
        'themes/jqt/img/whiteButton.png',
        'themes/jqt/img/loading.gif'
        ]
});

var activeScroll;
function setElements(nm){
	if (nm) { activeScroll = nm; } else { nm = activeScroll; }
	var footersize = 0;
	if ($('#'+nm+' > .footer').length){
		footersize = 40;
	}
	$('#'+nm+'_iscrollcontents').height($(window).height()-40-footersize);
	setTimeout(function(){eval(nm+'_iscroll.refresh()');},1);
}
function setScroll(nm){
	if($('#'+nm+'_iscrollcontents').length == 0){
		if($('#'+nm+' > .content').length){
			$('#'+nm+' > .content').attr('id',nm+'_iscrollcontents');
			eval(nm+'_iscroll = new iScroll(\''+nm+'_iscrollcontents\')');
			setElements(nm);
		}
	}else{
		setElements(nm);
	}
}

// Some sample Javascript functions:
$(function(){
	//common setting...
	$('.footer').html($('#jqtfooter').html());
	
	//Event block
	document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
	document.addEventListener('mousedown', function (e) { e.preventDefault(); }, false);
	document.addEventListener('mouseup', function (e) { e.preventDefault(); }, false);
	document.addEventListener('mouseover', function (e) { e.preventDefault(); }, false);
	document.addEventListener('mouseout', function (e) { e.preventDefault(); }, false);
	document.addEventListener('click', function (e) { e.preventDefault(); }, false);
	
	//iscroll setting...
	setScroll('goodslist');
	//세로,가로모드전환시
   	window.addEventListener('onorientationchange' in window ? 'orientationchange' : 'resize', function(){setElements(false);}, false);
    
    //카테고리창 호출
    $('.callcategory').tap(function(){
    	$('.floaty').css('opacity',100);
        $('.floaty').toggleFloaty();
        $(this).removeClass('active');
        return false;
    });
    $('.floaty').css('opacity',0).makeFloaty({
        spacing: 10,
        time: '0.1s'
    });
    $('.floaty').hideFloaty();
    
    //바둑판리스트형 보기 버튼
    $('#listtoggle').tap(function(){
    	if($('#goodslist .content ul.grid').length){
    		$('#goodslist .content ul.list').removeClass('grid');
    		$('.goodsinfo').show();
    	}else{
    		$('#goodslist .content ul.list').addClass('grid');
    		$('.goodsinfo').hide();
    	}
    });
    
});